﻿#region Opis pliku
//-----------------------------------------------------------------------------
// Missile.cs
// Autor: Jan Fraś
// 30.10.2012
//-----------------------------------------------------------------------------
#endregion

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;

namespace pogra
{
    /// <summary>
    /// klasa reprezentująca rakeity śmigłowca
    /// w każdej iteracji zostawia w danej lokalizacji emiter odpowiadający za dym
    /// </summary>
    class Missile:Bullet
    {
        Vector2 position;
        float velocity = 0.5f;

        public Missile(int power, float rotation, Entity target, Unit owner, ParticleSystem particleSystem) :
            base(power, rotation, target, owner, particleSystem )
        {
            position = owner.Position;
            rotation = owner.Rotation;
        }

        public override void Update(TimeSpan time)
        {
            rotation = (float)((Math.Atan2(target.Position.Y - position.Y, target.Position.X - position.X) + Math.PI * 2) % (Math.PI * 2));
            if (velocity < 3) velocity += 0.05f;
            position += new Vector2((float)Math.Cos(rotation), (float)Math.Sin(rotation)) * velocity * (float)time.Milliseconds;

            if((target.Position - position).Length() < velocity*time.Milliseconds)
            {
                used = true;
                base.Update(time);
            }
            particleSystem.AddEmitter(new SmokeEmitter(position, rotation));
            
        }

        public override void Draw(ExtendedSpriteBatch exSpriteBatch)
        {
            exSpriteBatch.DrawRectangle(new Rectangle((int)position.X, (int)position.Y, 3, 3), Color.White);
            base.Draw(exSpriteBatch);
        }
    }
}
